package com.yeguang.WXApp.controller.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.zeromq.ZMQ;

import com.alibaba.fastjson.JSON;
import com.yeguang.WXApp.controller.model.LbsInfo;

@Component("LbsService")
public class LbsService {
	@Value("#{configProperties['lbs.host']}")
	String mLbsHost;
	
	@Value("#{configProperties['lbs.port']}")
	String mLbsPort;	

	ZMQ.Context mContext;
	ZMQ.Socket mSocket;
	
	public LbsService()
	{
		mContext = ZMQ.context(1);
		mSocket = mContext.socket(ZMQ.REQ);
		mSocket.connect("tcp://" + mLbsHost + ":" + mLbsPort);
		mSocket.setReceiveTimeOut(4000);
	}
	
	public String getBusRoute(LbsInfo info){
		mSocket.send(JSON.toJSONString(info));	
		String res = mSocket.recvStr();
		return res.length() == 0 ? null:res;
	}
}
